package com.xx.controller;

import com.xx.entity.Student;
import com.xx.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import java.util.List;
/**
 * @author 许欣
 * 时间：2022/5/3 10:34
 * 描述：
 */
@Controller
@RequestMapping("/student")
public class StudentController {
    @Resource
    private StudentService studentService;

    @RequestMapping("/list")
    public String getAllBooks(Model model) {
        List<Student> list = studentService.findAll();
        model.addAttribute("list", list);
        return "list";
    }

    @RequestMapping("/toUpdate")
    public String toUpdate(int sid, Model model) {
        Student student =studentService.findById(sid);
        model.addAttribute("info", student);
        return "update";
    }

    //修改
    @RequestMapping("/update")
    public String update(Student student) {
        studentService.update(student);
        return "redirect:/student/list";
    }
    //删除
    @RequestMapping("/del/{sid}")
    public String del(@PathVariable Integer sid) {
        studentService.del(sid);
        return "redirect:/student/list";
    }

}
